<%-- 
    Document   : check_registro
    Created on : 22-feb-2012, 15:12:22
    Author     : Deico
--%>

<%@page import="usuario.paciente"%>
<%@page import="conexion.DB"%>
<%@page import="validacion.vrut"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*,java.io.*,java.lang.*,java.sql.*,usuario.login,java.sql.*"%>
    
    <%
        String rut=request.getParameter("rut"); 
        String pass=request.getParameter("pass");
        String pass2=request.getParameter("pass2");
        if(vrut.isRut(rut) &&
            pass.equalsIgnoreCase(pass2) && !paciente.isExist(rut))      
        {
                Calendar ahoraCal = Calendar.getInstance();
                ahoraCal.set(Integer.parseInt(request.getParameter("year")),
                Integer.parseInt(request.getParameter("month")),
                Integer.parseInt(request.getParameter("day")));
                java.util.Date fechan = ahoraCal.getTime();
           login.nuevoUsuario(rut, pass, "paciente",request.getParameter("email"));
         try {

            PreparedStatement prep = DB.DB_CONNECTION.prepareStatement(
            "insert into paciente values (?,?,?,?,?,?,?,?,?,?,?,?);");
             
            prep.setString(1,request.getParameter("rut"));
            prep.setString(2,request.getParameter("nombre"));
            prep.setString(3,request.getParameter("apellidoP"));
            prep.setString(4,request.getParameter("apellidoM"));
            prep.setDate(5,new java.sql.Date(fechan.getTime()));
            prep.setString(6,request.getParameter("direccion"));
            prep.setString(7,request.getParameter("telefono"));            
            prep.setString(8,request.getParameter("email"));
            prep.setString(9,request.getParameter("escolaridad"));   
            prep.setString(10,request.getParameter("ocupacion"));
            prep.setString(11,request.getParameter("estadoc"));
            prep.setString(12,request.getParameter("prevision"));
            prep.executeUpdate();
            
            } catch (SQLException ex) {
            System.out.println(ex);
        }
    %>
      
        <jsp:forward page="r_completo.jsp">
            <jsp:param name="Correcto" value="Validacion correcta"/>                
        </jsp:forward>
    <%        
            }
            else
            {
                 %>
        <jsp:forward page="error.jsp">
            <jsp:param name="Error" value="Es Obligatorio identificarse"/>                
        </jsp:forward>
    <% 
            }   
     %>
